//
//  SDBoundNumberLinkView.m
//  skinDetection
//
//  Created by  liangzhun on 2018/10/29.
//  Copyright © 2018年  liangzhun. All rights reserved.
//

#import "SDBoundNumberLinkView.h"
#import "SDUserProtocolVC.h"
@implementation SDBoundNumberLinkView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setViews];
    }
    return self;
}
- (void)setViews
{
    self.selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.selectBtn.selected = YES;
    [self.selectBtn setImage:[UIImage imageNamed:@"椭圆 2"] forState:UIControlStateNormal];
    [self.selectBtn setImage:[UIImage imageNamed:@"选中 拷贝"] forState:UIControlStateSelected];
    [self.selectBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        self.selectBtn.selected = !self.selectBtn.selected;
    }];
    [self addSubview:self.selectBtn];
    
    self.linkLab = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
    self.linkLab.textColor = SDMainTextColor;
    self.linkLab.font = Font(12);
    self.linkLab.numberOfLines =0;
    self.linkLab.lineBreakMode = NSLineBreakByWordWrapping;
   
    NSString *linkText = @"绑定代表您同意《悦慕服务使用协议》";
    self.linkLab.enabledTextCheckingTypes = NSTextCheckingTypePhoneNumber|NSTextCheckingTypeAddress|NSTextCheckingTypeLink;
    //链接正常状态文本属性
    self.linkLab.linkAttributes = @{NSForegroundColorAttributeName:SDMainColor};
    //链接高亮状态文本属性
    self.linkLab.activeLinkAttributes = @{NSForegroundColorAttributeName:SDMainColor};
    self.linkLab.text = linkText;
    TTTAttributedLabelLink *link1 = [self.linkLab addLinkToURL:nil withRange:[linkText rangeOfString:@"悦慕服务使用协议"]];
    link1.linkTapBlock = ^(TTTAttributedLabel *label, TTTAttributedLabelLink *link) {
        
        SDUserProtocolVC *vc = [SDMethodTool getViewControlWithIdentifier:NSStringFromClass([SDUserProtocolVC class])];
        UIViewController *nowVC = [SDMethodTool getCurrentVC];
        [nowVC.navigationController pushViewController:vc animated:YES];
        
    };
    [self.linkLab sizeToFit];
    
    [self addSubview:self.linkLab];
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self);
        make.height.width.mas_equalTo(15);
    }];
    
    [self.linkLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self.selectBtn.mas_right).offset(7);
        make.right.equalTo(self.mas_right).offset(0);
        make.height.mas_equalTo(15);
    }];
    
}
@end
